﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t301Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t301_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t301Mgr mgr = new t301Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t301(e.Parameters[t301_Filter.ParamPrefix]));
            IList<t301> list = mgr.FindAllByPage_t301(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t301_Filter.ParamPrefix]);
            t301_MainStore.DataSource = list;
            t301_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t301Mgr mgr = new t301Mgr();
            RowSelectionModel sm = t301_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t301 _t301 = new t301();
                _t301.t301_01 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t301(_t301))
                {
                    log.Debug("t301中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t301_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t301Mgr mgr = new t301Mgr();
            t301 _t301 = new t301();
            if (Hid.Text.Length > 0)
                _t301 = mgr.FindById_t301(int.Parse(Hid.Text));
            
			_t301.t301_02 = Txtt301_02.Text.Trim();
			_t301.t301_03 = Txtt301_03.Text.Trim();
			_t301.t301_04 = Txtt301_04.Text.Trim();
			_t301.t301_05 = Txtt301_05.Text.Trim();
			_t301.t301_06 = Txtt301_06.Text.Trim();
			_t301.t301_07 = Txtt301_07.Text.Trim();
			_t301.t301_08 = Txtt301_08.Text.Trim();
			_t301.t301_09 = Txtt301_09.Text.Trim();
			_t301.t301_10 = Txtt301_10.Text.Trim();
			_t301.t301_11 = Txtt301_11.Text.Trim();
			_t301.t301_12 = Txtt301_12.Text.Trim();
			_t301.t301_13 = Txtt301_13.Text.Trim();
			_t301.t301_14 = Txtt301_14.Text.Trim();
			_t301.t301_15 = Txtt301_15.Text.Trim();
			_t301.t301_16 = Txtt301_16.Text.Trim();
			_t301.t301_17 = Txtt301_17.Text.Trim();
			_t301.t301_18 = Txtt301_18.Text.Trim();
			_t301.t301_19 = Txtt301_19.Text.Trim();
			_t301.t301_20 = Txtt301_20.Text.Trim();
			_t301.t301_21 = Txtt301_21.Text.Trim();
			_t301.t301_22 = Txtt301_22.Text.Trim();
			_t301.t301_23 = Txtt301_23.Text.Trim();
			_t301.t301_24 = Txtt301_24.Text.Trim();
			_t301.t301_25 = Txtt301_25.Text.Trim();
			_t301.t301_26 = Txtt301_26.Text.Trim();
			_t301.t301_27 = Txtt301_27.Text.Trim();
			_t301.t301_28 = Txtt301_28.Text.Trim();
			_t301.t301_29 = Txtt301_29.Text.Trim();
			_t301.t301_30 = Txtt301_30.Text.Trim();
			_t301.t301_31 = Txtt301_31.Text.Trim();
			_t301.t301_32 = Txtt301_32.Text.Trim();
			_t301.t301_70 = Txtt301_70.Text.Trim();
			_t301.t301_71 = Txtt301_71.Text.Trim();
			_t301.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t301(_t301);
            else
                isok = mgr.Add_t301(_t301);
            if (isok)
            {
                t301_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t301中执行了保存（插入或修改），并成功");
                t301_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}